package cc.vv.btpartyjob.partymanager.delegate

import android.support.v4.widget.SwipeRefreshLayout
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.text.TextUtils
import android.view.View
import android.widget.TextView
import cc.vv.baselibrary.util.ColorUtil
import cc.vv.baselibrary.util.LKTimeUtil
import cc.vv.btpartyjob.partymanager.R
import cc.vv.btpartyjob.partymanager.adapter.WorkGoingAdapter
import cc.vv.btpartyjob.partymanager.moudel.bean.SiZhiDuiWuBean
import cc.vv.mvp.delegate.BaseAppDelegate
import com.chad.library.adapter.base.BaseQuickAdapter

/**
 * 工作情况Delegate
 * Created by Chen.qi on 2018/10/27.
 */
class WorkGoingFragmentDelegate : BaseAppDelegate() {
    override fun initWidget() {
    }

    override fun initLayoutRes(): Int {
        return R.layout.fragment_sizhi_duiwu_list
    }


    /**
     * 设置刷新监听
     */
    fun bindRefreshListener(listener: SwipeRefreshLayout.OnRefreshListener) {
        val refresh = getView<SwipeRefreshLayout>(R.id.srl_fsdL_swipeLay)
        refresh?.setOnRefreshListener(listener)
        refresh?.setColorSchemeColors(ColorUtil.setBCColor(R.color.color_FA555C))
    }

    /**
     * 设置刷新停止
     */
    fun stopRefreshing() {
        val refresh = getView<SwipeRefreshLayout>(R.id.srl_fsdL_swipeLay)
        refresh?.isRefreshing = false
    }

    /**
     * 设置加载更多监听
     */
    fun bindLoadMore(mAdapter: WorkGoingAdapter?, loadMoreListener: BaseQuickAdapter.RequestLoadMoreListener) {
        val recyclerView = getView<RecyclerView>(R.id.rv_fsdL_listData)
        if (null != recyclerView) {
            mAdapter?.setOnLoadMoreListener(loadMoreListener, recyclerView)
        }
    }


    /** 设置适配器*/
    fun setRecyclerViewAdapter(mAdapter: WorkGoingAdapter?) {
        if (null != mAdapter) {
            val recyclerView = getView<RecyclerView>(R.id.rv_fsdL_listData)
            recyclerView?.layoutManager = LinearLayoutManager(context)
            recyclerView?.adapter = mAdapter
        }
    }


    /** 数据适配器 */
    fun setAdapterData(mAdapter: WorkGoingAdapter?, list: List<SiZhiDuiWuBean>?) {
        if (null != list) {
            mAdapter?.setNewData(list)
            if (list.isEmpty()) {
                showNoDataView(true)
            } else {
                showNoDataView(false)
            }
        } else {
            showNoDataView(true)
        }
    }


    /** 显示暂无数据缺省页 */
    private fun showNoDataView(isNoData: Boolean) {
        val noData = getView<TextView>(R.id.btv_fsdL_listNoData)
        if (isNoData) {
            noData?.visibility = View.VISIBLE
        } else {
            noData?.visibility = View.GONE
        }
    }

    /**
     * 设置开始时间
     */
    fun setStartTime(time: String?) {
        val tvStart = getView<TextView>(R.id.tv_fsdL_startTime)
        if (TextUtils.isEmpty(time)) {
            tvStart?.text = LKTimeUtil.getInstance().formatTime("yyyy-MM-dd", System.currentTimeMillis())
        } else {
            tvStart?.text = time
        }
    }

    /**
     * 设置开始时间
     */
    fun setEndTime(time: String?) {
        val tvEnd = getView<TextView>(R.id.tv_fsdL_endTime)
        if (TextUtils.isEmpty(time)) {
            tvEnd?.text = LKTimeUtil.getInstance().formatTime("yyyy-MM-dd", System.currentTimeMillis())
        } else {
            tvEnd?.text = time
        }
    }

}